<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../js/vue-2.6.12.js"></script>
  <script src="../js/vue-router.js"></script>
  
</head>
<body>
  <div id="app">
    <router-view></router-view>
  </div>
  <template id="loginform">
    <form action="" @submit.prevent="handleLogin">
        用户名: <input type="text" > <br>
        密码: <input type="password"> <br>
        <input type="submit" value="登录">
        <router-link to="/register">注册</router-link>
    </form>
  </template>

  <template id="register-form">
    <form action="" @submit.prevent="handleRegister">
        用户名: <input type="text" > <br>
        密码: <input type="password" > <br>
        确认密码: <input type="password" > <br>
        <input type="submit" value="注册">   
        <router-link to="/login">登录</router-link>
    </form>
  </template>
  <script type="text/javascript">
    var loginform = {
      template:"#loginform",
      methods:{
        handleLogin:function(){
          window.location="http://www.baidu.com";
        }
      }
    };
    var registerform = {
      template:"#register-form",
      methods:{
        handleRegister:function(){
          this.$router.push("/login");
        }
      }
    };
    var router = new VueRouter({
      routes:[
        {name:"default",path:"/",redirect:"/login"},
        {name:"login",path:"/login",component:loginform},
        {name:"register",path:"/register",component:registerform},
      ]
    });
    const vm = new Vue({
      el:"#app",
      router:router
    });

  </script>
</body>
</html>